from uuid import UUID

from PyQt5.QtWidgets import QVBoxLayout, QLabel, QDialog, QLineEdit
from data import database

class GenreEditor(QDialog):
    COMBO_BOX_UUID_ROLE = 1

    def __init__(self, uuid: UUID):
        super().__init__(None)
        self.setWindowTitle('Genre Editor')

        self.uuid: UUID = uuid

        #region
        layout = QVBoxLayout()

        self.uuid_label = QLabel()
        self.uuid_label.setText('Genre UUID')
        layout.addWidget(self.uuid_label)

        self.uuid_view = QLineEdit()
        self.uuid_view.setText(str(self.uuid))
        self.uuid_view.setReadOnly(True)
        layout.addWidget(self.uuid_view)

        self.name_label = QLabel()
        self.name_label.setText('Genre Name')
        layout.addWidget(self.name_label)

        self.name_edit = QLineEdit()
        self.name_edit.setPlaceholderText('Enter album name here')
        self.name_edit.setText(database['genres'][self.uuid]['name'])
        self.name_edit.editingFinished.connect(self.genre_name_changed)
        layout.addWidget(self.name_edit)

        self.setLayout(layout)
        #endregion

    def genre_name_changed(self):
        text = self.name_edit.text()
        database['genres'][self.uuid]['name'] = text
